package com.demo.entity;

import com.demo.utils.HttpStatus;
import com.demo.utils.StringUtils;

import java.util.HashMap;
import java.util.Objects;

/**
 * 操作消息提醒
 *
 * @param <T> 数据对象的类型
 */
public class AjaxResult<T> {
    private int code;
    private String msg;
    private T data;

    // Default constructor
    public AjaxResult() {
    }

    // Constructor with code and msg
    public AjaxResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // Constructor with code, msg, and data
    public AjaxResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> AjaxResult<T> success() {
        return new AjaxResult<>(200, "操作成功");
    }

    public static <T> AjaxResult<T> success(T data) {
        return new AjaxResult<>(200, "操作成功", data);
    }

    public static <T> AjaxResult<T> success(String msg) {
        return new AjaxResult<>(200, msg);
    }

    public static <T> AjaxResult<T> success(String msg, T data) {
        return new AjaxResult<>(200, msg, data);
    }

    public static <T> AjaxResult<T> warn(String msg) {
        return new AjaxResult<>(400, msg);
    }

    public static <T> AjaxResult<T> warn(String msg, T data) {
        return new AjaxResult<>(400, msg, data);
    }

    public static <T> AjaxResult<T> error() {
        return new AjaxResult<>(500, "Operation failed");
    }

    public static <T> AjaxResult<T> error(String msg) {
        return new AjaxResult<>(500, msg);
    }

    public static <T> AjaxResult<T> error(String msg, T data) {
        return new AjaxResult<>(500, msg, data);
    }

    // Getters and setters
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "AjaxResult{" + "code=" + code + ", msg='" + msg + '\'' + ", data=" + data + '}';
    }
}

